package com.ph.irp.base.verifyproject.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.verifyproject.service.PBaseVerifyprojectCashService;
import com.ph.irp.dto.PageDTO;
import com.ph.irp.model.PBaseVerifyprojectCashrunoff;
import com.ph.util.pagination.PageUtil;
import com.ph.util.pagination.ShowPageList;

public class VerifyprojectCashAction extends ActionSupport implements ShowPageList{
	private String FORWARD = null;
	private PBaseVerifyprojectCashrunoff cashModel;
	private PBaseVerifyprojectCashService cashService;
	private List<PBaseVerifyprojectCashrunoff> cashList;
	private List<PBaseVerifyprojectCashrunoff> tempCashList;
	private String[] rowlist;
	private PageDTO page;
	private String cpage;
	
	public PageDTO getPage() {
		return page;
	}

	public void setPage(PageDTO page) {
		this.page = page;
	}

	public String getCpage() {
		return cpage;
	}

	public void setCpage(String cpage) {
		this.cpage = cpage;
	}

	public String[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(String[] rowlist) {
		this.rowlist = rowlist;
	}

	public List<PBaseVerifyprojectCashrunoff> getCashList() {
		return cashList;
	}

	public void setCashList(List<PBaseVerifyprojectCashrunoff> cashList) {
		this.cashList = cashList;
	}

	public PBaseVerifyprojectCashrunoff getCashModel() {
		return cashModel;
	}

	public void setCashModel(PBaseVerifyprojectCashrunoff cashModel) {
		this.cashModel = cashModel;
	}

	public PBaseVerifyprojectCashService getCashService() {
		return cashService;
	}

	public void setCashService(PBaseVerifyprojectCashService cashService) {
		this.cashService = cashService;
	}

	public String addInput() throws Throwable {

		return "addInput";
	}

	public String showCashList() throws Throwable {
		tempCashList = cashService.getAllCash();
		page = PageUtil.generatePageDTO(tempCashList, "showCashPageList.action", cpage);
		cashList = page.getResList();
		FORWARD = "success";
		return "success";
	}
	
	public String showPageList() throws Throwable {
		if (tempCashList != null) {
			page = PageUtil.generatePageDTO(tempCashList,
					"showCashPageList.action", cpage);
			cashList = page.getResList();
			FORWARD = "success";
		} else {
			FORWARD = "input";
		}
		return FORWARD;
	}

	public String getCashByCondition() throws Throwable {
		tempCashList = cashService.getCashByCodeAndName(cashModel);
		page = PageUtil.generatePageDTO(tempCashList, "showCashPageList.action", cpage);
		cashList = page.getResList();
		cashModel=null;
		FORWARD = "success";
		return "success";
	}

	public String addCash() throws Throwable {
		cashService.addCash(cashModel);
		FORWARD = "success";
		return "success";
	}

	public String select() throws Throwable {
		tempCashList = cashService.getAllCash();
		page = PageUtil.generatePageDTO(tempCashList, "showCashPageList.action", cpage);
		cashList = page.getResList();
		FORWARD = "success";
		return "select";
	}

	public String showEditCash() throws Throwable {
		cashModel = cashService.getCashById(Integer
				.valueOf((String) rowlist[0]));
		return "success";
	}

	public String editCash() throws Throwable {
		cashService.updateCash(cashModel);
		FORWARD = "success";
		return "success";
	}

	public String deleteCash() throws Throwable {
		cashService.deleteCash(rowlist);
		return "success";
	}
}
